﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="copyright" content=""/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>活动管理</title>
    <link href="<%=path%>/favicon.ico" rel="shortcut icon">
   <link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <%--<link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/public.css" />--%>
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/activity.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/marketing.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/style_list.css" /> 
    
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">	
    
</head>
<body class="gray-bg">
 <div class="wrapper wrapper-content animated fadeInRight">
 
    <div class="container-fluid">
       
            <div class="row">  
                <div class="col-md-12">
			     <div class="ibox">	
				    <div class="ibox-content text-right">
				      <h3>
						<span>
							<button type="button" class="btn btn-primary" onclick="window.location.href='<%=basePath%>/view/ui/chooseActivityTemplate'">重新选择模板</button>
						</span>
					  </h3>
				    </div>
			     </div>   
			   </div>
                         
                <div hidden="" class="x_progress x_basics">
                    <!--步骤-->
                    <div class="progress">
                        <div class="progress-bar progress-bar-warning" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
                             >
                            <span class="sr-only_1">1</span>
                            <p class="x_color_bz">选择模板</p>
                        </div>
                        <div class="progress-bar progress-bar-warning" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
                             >
                            <span class="sr-only_1">2</span>
                            <p class="x_color_bz">编辑内容</p>
                        </div>
                        <div class="progress-bar progress-bar-warning" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
                             >
                            <span class="sr-only_1">3</span>
                            <p class="x_color_bz ">分享设置</p>
                        </div>
                        <div class="progress-bar progress-bar-warning" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
                             >
                            <span class="sr-only_1">4</span>
                            <p class="x_color_bz x_color_dq" style="color:#ffc105;">活动预览</p>
                        </div>
                        <div class="progress-bar progress-bar-info" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
                             >
                            <span class="sr-only_2">√</span>
                            <p class="x_color_bz">分享</p>
                        </div>
                    </div>
                    <!--步骤end-->
                </div>
                <div class="col-md-12 white-bg ">
                    <!--内容左侧-->
                    <div class="col-md-6">
                       
                        <div class="k_left_title">
                            <span></span>
                           <!--  <h6 id="activity_title">优惠活动转发有礼</h6> -->
                        </div>
                        <div class="s_activity_body s_left_phone">
                            <div id="editor">
                            </div>
                            <div class="s_slide" style="height:250px">

                            </div>
                           
                            

                            <div class="k_activity">
                             
                                
                                <div id="button_info" >
                               
                                </div>
                            </div>

                            <ul class="s_footer">
                              
                            </ul>
                            
                        </div>
                    </div>
                    <!--内容左侧end-->
                    
                    <div class="col-md-6 text-right" style="margin-top:20px">
                      <button id="re-edit" type="button" class="btn  btn-w-m btn-outline btn-primary">重新编辑</button>
                      <button id="share_now" type="button" class="btn btn-w-m btn-primary" onclick="javascript:shareActivity()">立即分享</button>
                    </div>
                </div>
            </div>
    </div> 
   
   </div>
    <!-- 立刻分享弹框 -->
   <div hidden="" class="modal inmodal fade" id="share_modal" tabindex="-1" role="dialog"  aria-hidden="true">
	    <div class="modal-dialog modal-sm">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
	                <h4 class="modal-title">扫一扫立刻分享</h4>
	            </div>
	            <div class="modal-body text-center">
	               <div id="qrcode"></div>
	               <div style="margin-top:15px;margin-left:10px;margin-bottom:20px">
	                   <h5 style="float: left;width:15%;margin-top:10px">链接</h5>
	                   <input id="shortUrl" type="text" class="input form-control" style="float: left;width:55%;" readonly="readonly">
	                   <button id="btnCopy" class="btn btn-primary" type="button" style="float: left;width:25%;margin-left:5%" data-clipboard-action="copy" data-clipboard-target="#shortUrl">复制链接</button>
	               </div>
	                <div style="margin-top:10px;">
	                   <button class="btn btn-primary" type="button" style="width:25%;margin-right: 5%;margin-top: 15px;" onclick="javascript:intentSocialSms();">群发短信</button>
	               </div>
	            </div>
	        </div>
	    </div>
	</div>  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="<%=path%>/js/marketing/swiper-3.2.7.min.js"></script>
	<script src="<%=path%>/js/marketing/jquery.iosslider.js"></script>
	<script src="<%=path%>/js/marketing/jquery.lt_slide.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>

	<script type="text/javascript" src="<%=path%>/js/marketing/html2canvas.js"></script>
	<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.js"></script>
    <script>
        $('#share_now').click(function () {
            $('#shareModal').modal('show');
            activateActivity();
        });
        $('.x_popup .issue span').click(function () {
             $('.x_popup').hide();
            $('.issue').hide(); 
        });
        //重新编辑photoAlbum?type=activity&activity_id=102
        $('#re-edit').click(function () {
        	if(tag=="defined_text"){
        		window.location.href = "<%=path%>/view/ui/createModel?operationType=edit&type=activity&&activity_id="+activity_id;
        	}else if(tag=="defined_pic"){
        		window.location.href = "<%=path%>/view/ui/photoAlbum?type=activity&activity_id="+activity_id;
        	}else{
        		window.location.href = "<%=path%>/api/bm/ui/createActivity2?type=edit&&activity_id="+activity_id;
        	}
        	
       });
        //重新选择模板
        $('#re_chose_model').click(function () {
        	 window.location.href="<%=path%>view/ui/chooseActivityTemplate";
       });
        
        var activity_id;
        var access_token=$.cookie('access_token');
 	    var cid=$.cookie('cid');
 	    var uid=$.cookie('uid');
        var tag;
        var activityLongUrl="";
        $(function(){
     	   //获取活动id
     	  activity_id=getQueryString("activity_id");
     	  getActivityInfo(activity_id);
     	  activityStore();
        });
        //获取活动信息
        function getActivityInfo(activity_id) {
			var url="<%=path%>/activity/ajaxActivityDetail";
			$.post(url, {
				"id" : activity_id,
			}, function(data) {
				
				if (data.status == 200 && data.data!=undefined) {
					setActivityHtml(data.data);
				} else {
				}
			});
		}
        
      //设置活动信息
		function setActivityHtml(data) {
    	    tag=data.activityType;
			var title='';
			var description='';
			var activity_detail_rule='';
			var activity_title='';
			
			activityLongUrl=data.webUrl;
			/* if(tag=="defined_text"){ */
				$('.s_slide').hide();
				$('#environmental').hide();
				$('.s_rule').hide();
				$('#price').hide();
				$('.s_hdjs').hide();
				$('.k_title1').hide();
				$('.k_left_title').hide();
				$('#h3-price').hide();


				$('#editor').html(data.description.replace(/<img /g, '<img crossOrigin="anonymous" '));
				console.log(data.description);
				
				if(StringEmpty(data.remarks)){
					background_color=data.remarks;
					$(".s_activity_body").css("background-color",background_color);
					$(".k_activity").css("background-color",background_color);
				}
				
				
				// $('#editor').find("img").attr("crossOrigin","anonymous");
				
				//html2canvas截图
				html2canvas(document.getElementById('editor'), {
		    		allowTaint: true,
		    		taintTest: false,
		    		onrendered: function(canvas) {
			    		//debugger;
			    		try{
			    			//生成base64图片数据
				    		var dataUrl = canvas.toDataURL('image/png');
						    /* canvas.style.width = "119px";
						    canvas.style.height = "192px"; */ 
			    			//document.getElementById("show_canvas").append(canvas);
			    			$.ajax({
			                    url:'<%=path%>/activityDefinedTemplate/ajaxScreenShot',
			                    type:'POST',
			                    data:{
			                        base64ImgData : JSON.stringify(dataUrl)
			                    },
			                    success:function(msg){
									console.log(msg.pic_url);
									console.log(msg.error_code);
									console.log(msg.error_msg);
									//已分享图片作为活动图片
									<%-- $.ajax({
										url:'<%=path%>/activity/editActivity',
										type:'POST',
										data:{
											"head_pic":data.pic_url,
											"cid":cid,
											"activity_id":activity_id,
											"uid":uid,
											"access_token":access_token
										},
										success:function(msg2){
											console.log(jQuery.parseJSON(msg2));
										},
										error:function(){
											console.log("false---pic");
										}
									}) --%>
			                    },
			                    error:function(XMLHttpRequest){
			                    	console.log(XMLHttpRequest);
			                    }
			                });
			    		}catch(err){
			    			console.log("有canvas跨域图片链接");
			    			console.log("异常信息--->"+err);
			    		}
		    		}
		    	});
			<%-- }else{
				description += data.description;
				activity_detail_rule +=data.description;
				activity_title+='<span></span><h6>'+data.title+'</h6>';
				title+='<p><img src="<%=path%>/images/marketing/icon_home.png"/>'
					+ data.name + '</p>';
				/* $('.k_left_title').html(activity_title); */
				$('#activity_description').html(data.description);
				$('#activity_detail_rule').html(data.description);
				$('.k_title1').html(title);
			/* 	 $("#price").text(data.original_price);  */
			    console.log(data.discount_price);
			    console.log(data.original_price);
			    $("#unitPrice2").text(data.discount_price);
		        $("#groupPrice2").text(data.original_price);
				setBannerHtml(data.pic_url,data.receive_coupon);
				
				
				if(StringEmpty(data.equipment_facilities)){
					var temp=data.equipment_facilities;
					var equipment_facilities=temp.split(",");
					var equipmenHtml='';
					for(var i in equipment_facilities){
						equipmenHtml+='<span><img src="<%=path%>/images/marketing/s_dg.png" />'+equipment_facilities[i]+'</span>';
					}
					$('#equipment_facilities').html(equipmenHtml);
				}else{
					$('#equipment_facilities').hide();
				}
				
			} --%>
			if(StringEmpty(data.weixinQrcode)&&!StringEmpty(data.weiboQrcode)){
				console.log("weixin--->");
				var html_weixin='<li style="width:100%"><img id="weixin_qrcode" src="'+data.weixinQrcode+'" /><p>微信二维码</p></li>';
				$(".s_footer").append(html_weixin); 
			}else if(StringEmpty(data.weixinQrcode)){
				var html_weixin='<li><img id="weixin_qrcode" src="'+data.weixinQrcode+'" /><p>微信二维码</p></li>';
				$(".s_footer").append(html_weixin); 
			}
			
            if(StringEmpty(data.weiboQrcode)&&!StringEmpty(data.weixinQrcode)){
            	console.log("weibo_qrcode");
            	var html_weibo='<li style="width:100%"><img id="weibo_qrcode" src="'+data.weiboQrcode+'" /><p>微博二维码</p></li>';
				$(".s_footer").append(html_weibo); 
			}else if(StringEmpty(data.weiboQrcode)){
				var html_weibo='<li><img id="weibo_qrcode" src="'+data.weiboQrcode+'" /><p>微博二维码</p></li>';
				$(".s_footer").append(html_weibo); 
			}
			
			
			var commit_info=data.commitInfo.split(",");
			console.log("-------->"+commit_info);
			if(StringEmpty(commit_info)&&commit_info.length>0){
				var button_html='';
				for(var i=0;i<commit_info.length;i++){
					switch (commit_info[i]) {
					
					case "commit_name":
						button_html+='<br><br><div class="s_name_input"><i>姓名</i><input type="email" /></div>';
						break;
                    case "commit_mobile":
                    	button_html+='<div class="s_name_input"><i>电话</i><input type="text" /></div>';
						break;
					case "commit_email":
						button_html+='<div class="s_name_input"><i>邮箱</i><input type="email" /></div>';
						break;
                    case "commit_weibo":
                    	button_html+='<div class="s_name_input"><i>微博</i><input type="text" /></div>';
						break;
                    case "commit_weixin":
                    	button_html+='<div class="s_name_input"><i>微信</i><input type="text" /></div>';
						break;
                    case "commit_job":
                    	button_html+='<div class="s_name_input"><i>职位</i><input type="text" /></div>';
						break;
                    case "commit_company":
                    	button_html+='<div class="s_name_input"><i>公司</i><input type="text" /></div>';
						break;
					default:
						break;
					}
				}
				button_html+='<div class="s_get_btn">'+(data.buttonText!=""? data.buttonText:"立即领取")+' </div>';
				$('#button_info').html(button_html);
				
				if(StringEmpty(data.buttonCss)&&data.buttonCss!="#000000")
				$(".s_get_btn").css("background-color",data.buttonCss);
			}else{
				$(".s_get_btn").hide();
			}
				
			
		}
		//设置轮播图
		function setBannerHtml(activity_pics,receive_coupon) {
			var html = '<ul id="banner" class="fix">';
			pics = activity_pics.split(",");
			for (var i = 0; i < pics.length; i++) {
				var pic=pics[i];
				html += '<li> <img src="'+pic+'" />';
				html += '<div class="s_slide_con">';
				html += '<p></p>';
				html += '<p></p>';
<%-- 				html += ' <a href="javascript:;"><img src="<%=path%>/images/marketing/icon_dh.png" />'+receive_coupon+'</a>';
				html += '<a href="javascript:;"><img src="<%=path%>/images/marketing/icon_heart.png" />'+receive_coupon+'</a>'; --%>
				html += '<h4></h4></div></li>';
			}
			html += '</ul>';
			$('.s_slide').html(html);
			/* $('.s_slide').lt_slide({
				autoSlide : true,
				autoSlideTimer : 300000
			}); */
		}
		
		 //获取活动门店信息
	    function activityStore(){
	    	var url = "<%=path%>/activityStore/ajaxListRelationActivityStore";
	    	$.post(url,{
				"activityId" : activity_id,
	    	},function(data){
	    		
	    		if(data.status == "200"){
	    			var stores=data.data;
	    			var html='';
	    	    	$('#li_address').text("地址:"+stores[0].address);
	    	    	$('#store_num').text("全部"+stores.length+"家分店");
	    		}else{
	    		}
	    	});
	    }
		
		 
	    //激活
        function activateActivity() {
			var url = "${pageContext.request.contextPath}/activity/activate";
			$.post(url, {
				"activity_id" : activity_id,
			}, function(data) {
				
				if (data.status == 200) {
				} else {
				}
			});
		}
		 
	    
        function shareActivity(){
        	var url="<%=path%>/activity/ajaxLongUrlToShort";
    		$.post(url, {
    			"longUrl" : activityLongUrl,
    		}, function(data) {
    			if (data.status == 200) {
    				var shortUrl=data.data;
    				$('#qrcode').html("");
    				$("#shortUrl").val(shortUrl);
               	    jQuery('#qrcode').qrcode(shortUrl);
               	    $('#share_modal').modal('show');
    			}else if(data.error_code=="20028"){
    				loginDialog();
	        	}else{
	        		errorDialog(data.message);
	        	}
    		});
        }
        //复制短链
		$(document).ready(function(){    
			var clipboard = new ClipboardJS('#btnCopy');
			   clipboard.on('success', function(e) {  
				   $('#share_modal').modal('hide');
				   successDialog("复制成功");
			   });  
			   clipboard.on('error', function(e) {  
				   $('#share_modal').modal('hide');
				   successDialog("复制失败！请手动复制");
			   });  
		}) 
		//跳转到群发短信
		function intentSocialSms(){
			window.location.href="<%=path%>/view/sms/choseSendObject?type=create&activityId="+activity_id;
		}
		 
		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return unescape(r[2]);
			return null;
		}
		//判断字符串是否为空
		function StringEmpty(content) {
			if (content == undefined || content == "" || content == null) {
				return false;
			} else {
				return true;
			}
		}
    </script>
</body>
</html>